//
//  MyOrderViewIndexViewController.m
//  DPGJ
//
//  Created by ZhuoLaiQiang@Gmail.com on 11-11-19.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "MyOrderViewIndexViewController.h"
#import "MyOrderAllOrderViewController.h"
#import "CONSTS.h"
#import "SearchOrderViewController.h"

@implementation MyOrderViewIndexViewController

@synthesize tableView               =       _tableView;
@synthesize tableViewDataSource     =       _tableViewDataSource;

#pragma mark - 系统函数
- (void)dealloc
{
    [_tableView release];
    LF_RELEASE_SAFELY(_tableViewDataSource);
    
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"我的订单";
    self.view.backgroundColor = [UIColor clearColor];
    
    self.tableViewDataSource = [NSArray arrayWithObjects: 
                                @"order_cell_all_deal.png", 
                                @"order_cell_watting_send.png",
                                @"order_cell_watting_pay.png", 
                                @"order_cell_refund_deal.png",
                                @"order_cell_end_send.png",
                                @"order_cell_success_deal.png",
                                @"order_cell_colse.png",
                                @"order_cell_search_deal.png", nil];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear: animated];
    
    disSelctCell(_tableView);
}


- (void)viewDidUnload
{
    [self setTableView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}



#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_tableViewDataSource count];
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellSigin = @"cellSign";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellSigin];
    if (!cell)
    {
        cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: cellSigin] autorelease];
        UIImageView *imageView = [[[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 320, cell.frame.size.height)] autorelease];
        imageView.tag = MYORDERVIEWINDEXVIEWCONTROLLER_CELL_BACK_GROUND_IMAGE_TAG;
        [cell setBackgroundView: imageView];
        
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
    }
    
    NSInteger row = [indexPath row];
    
    NSString *imageName = [_tableViewDataSource objectAtIndex: row];
    UIImage *image = [UIImage imageNamed: imageName];
    
    UIImageView *cellBackGroundImageView = (UIImageView *)[cell viewWithTag: MYORDERVIEWINDEXVIEWCONTROLLER_CELL_BACK_GROUND_IMAGE_TAG];
    cellBackGroundImageView.image = image;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 51;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /*
     #define  TRADE_NO_CREATE_PAY            @"没有创建支付宝交易"
     #define  WAIT_BUYER_PAY                 @"等待买家付款"
     #define  WAIT_SELLER_SEND_GOODS         @"等待卖家发货,即:买家已付款"
     #define  WAIT_BUYER_CONFIRM_GOODS       @"等待买家确认收货,即:卖家已发货"
     #define  TRADE_BUYER_SIGNED             @"买家已签收,货到付款专用"
     #define  TRADE_FINISHED                 @"交易成功"
     #define  TRADE_CLOSED                   @"付款以后用户退款成功，交易自动关闭"
     #define  TRADE_CLOSED_BY_TAOBAO         @"付款以前，卖家或买家主动关闭交易"
     */
    NSInteger row = [indexPath row];
    
    switch (row)
    {
        case 0:
        {
            MyOrderAllOrderViewController *MyOrderAllOrderVC = [[[MyOrderAllOrderViewController alloc] init] autorelease];
            [self.navigationController pushViewController: MyOrderAllOrderVC animated: YES];
            break;
        }
        case 1:
        {
            MyOrderAllOrderViewController *MyOrderAllOrderVC = [[[MyOrderAllOrderViewController alloc] initWithStatus: @"WAIT_SELLER_SEND_GOODS"] autorelease];
            [self.navigationController pushViewController: MyOrderAllOrderVC animated: YES];
            break;
        }
        case 2:
        {
            MyOrderAllOrderViewController *MyOrderAllOrderVC = [[[MyOrderAllOrderViewController alloc] initWithStatus: @"WAIT_BUYER_PAY"] autorelease];
            [self.navigationController pushViewController: MyOrderAllOrderVC animated: YES];   
            break;
        }
        case 3:
        {
//退款成功后，关闭的交易
            MyOrderAllOrderViewController *MyOrderAllOrderVC = [[[MyOrderAllOrderViewController alloc] initWithStatus: @"TRADE_CLOSED"] autorelease];
            [self.navigationController pushViewController: MyOrderAllOrderVC animated: YES]; 
            
            break;
        }
        case 4:
        {
            MyOrderAllOrderViewController *MyOrderAllOrderVC = [[[MyOrderAllOrderViewController alloc] initWithStatus: @"WAIT_BUYER_CONFIRM_GOODS"] autorelease];
            [self.navigationController pushViewController: MyOrderAllOrderVC animated: YES];   
            break;
        }
        case 5:
        {
            MyOrderAllOrderViewController *MyOrderAllOrderVC = [[[MyOrderAllOrderViewController alloc] initWithStatus: @"TRADE_FINISHED"] autorelease];
            [self.navigationController pushViewController: MyOrderAllOrderVC animated: YES];  
            
            break;
        }
        case 6:
        {
            MyOrderAllOrderViewController *MyOrderAllOrderVC = [[[MyOrderAllOrderViewController alloc] initWithStatus: @"TRADE_CLOSED_BY_TAOBAO"] autorelease];
            [self.navigationController pushViewController: MyOrderAllOrderVC animated: YES];  
            
            break;
        }
        case 7:
        {
            //搜索订单
            SearchOrderViewController *searchOrderViewController = [[[SearchOrderViewController alloc] init] autorelease];
            [self.navigationController pushViewController: searchOrderViewController animated: YES];
            
            break;
        }
            
        default:
            break;
    }
}

@end
